import 'package:flutter/material.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        appBar: AppBar(
          title: Text("动画页面"),
        ),
        body: Column(
          children: <Widget>[
            RaisedButton(
              child: Text("CustomRoute5"),
              onPressed: () => Navigator.push(context, CustomRoute5(Page1())),
            ),
            RaisedButton(
              child: Text("CustomRoute4"),
              onPressed: () => Navigator.push(context, CustomRoute4(Page1())),
            ),
            RaisedButton(
              child: Text("CustomRoute3"),
              onPressed: () => Navigator.push(context, CustomRoute3(Page1())),
            ),
            RaisedButton(
              child: Text("CustomRoute2"),
              onPressed: () => Navigator.push(context, CustomRoute2(Page1())),
            ),
            RaisedButton(
              child: Text("CustomRoute1"),
              onPressed: () => Navigator.push(context, CustomRoute1(Page1())),
            ),
          ],
        ));
  }
}

class Page1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("动画二级页面"),
      ),
    );
  }
}

class CustomRoute1 extends PageRouteBuilder {
  final Widget widget;
  CustomRoute1(this.widget)
      : super(
            transitionDuration: const Duration(seconds: 1),
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return FadeTransition(
                opacity: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                    parent: animation1, curve: Curves.fastOutSlowIn)),
                child: child,
              );
            });
}

class CustomRoute2 extends PageRouteBuilder {
  final Widget widget;

  CustomRoute2(this.widget)
      : super(
            transitionDuration: const Duration(seconds: 1),
            pageBuilder: (BuildContext context, Animation<double> animation1,
                Animation<double> animation2) {
              return widget;
            },
            transitionsBuilder: (BuildContext context,
                Animation<double> animation1,
                Animation<double> animation2,
                Widget child) {
              return new SlideTransition(
                position: new Tween<Offset>(
                  begin: const Offset(1.0, 0.0),
                  end: const Offset(0.0, 0.0),
                ).animate(animation1),
                child: child,
              );
            });
}

class CustomRoute3 extends PageRouteBuilder {
  final Widget widget;
  CustomRoute3(this.widget)
      : super(
            pageBuilder: (context, animator, animator2) => widget,
            transitionsBuilder: (context, animation1, animation2, child) =>
                SlideTransition(
                  position: Tween<Offset>(
                          begin: Offset(-1.0, 0.0), end: Offset(0.0, 0.0))
                      .animate(CurvedAnimation(
                          parent: animation1, curve: Curves.fastOutSlowIn)),
                  child: child,
                ));
}

class CustomRoute4 extends PageRouteBuilder {
  final Widget widget;
  CustomRoute4(this.widget)
      : super(
            pageBuilder: (context, animator, animator2) => widget,
            transitionsBuilder: (context, animation1, animation2, child) =>
                SlideTransition(
                  position: Tween<Offset>(
                          begin: Offset(-1.0, 0.0), end: Offset(0.0, 0.0))
                      .animate(CurvedAnimation(
                          parent: animation1, curve: Curves.fastOutSlowIn)),
                  child: child,
                ));
}

class CustomRoute5 extends PageRouteBuilder {
  final Widget widget;
  CustomRoute5(this.widget)
      : super(
            pageBuilder: (context, animator, animator2) => widget,
            transitionsBuilder: (context, animation1, animation2, child) =>
                RotationTransition(
                    turns: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                        parent: animation1, curve: Curves.fastOutSlowIn)),
                    child: ScaleTransition(
                      scale: Tween(begin: 0.0, end: 1.0).animate(
                          CurvedAnimation(
                              parent: animation1, curve: Curves.fastOutSlowIn)),
                      child: child,
                    )));
}
